# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=balbuzard
pkgver=67.d6349ef1bc55
pkgrel=4
pkgdesc='A package of malware analysis tools in python to extract patterns of interest from suspicious files (IP addresses, domain names, known file headers, interesting strings, etc).'
arch=('any')
groups=('blackarch' 'blackarch-malware' 'blackarch-cracker'
        'blackarch-reversing')
url='https://bitbucket.org/decalage/balbuzard/'
license=('GPL')
depends=('python2' 'yara' 'python2-yara')
makedepends=('mercurial' 'python2-setuptools')
options=('!strip')
source=("hg+https://bitbucket.org/decalage/$pkgname")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(hg identify -n).$(hg identify -i) | cut -d ' ' -f 2- | tr -d ' '
}

package() {
  cd $pkgname

  _tools="balbuzard bbcrack bbharvest bbtrans"

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"
  install -dm 755 "$pkgdir/usr/share/doc/$pkgname"

  python2 setup.py install --root="$pkgdir" --optimize=1

  cp -a INSTALL.txt README.md balbuzard/README.html balbuzard/README.txt \
    balbuzard/doc/* "$pkgdir/usr/share/doc/$pkgname"

  rm -rf INSTALL.txt README.md balbuzard/README.html balbuzard/README.txt \
    balbuzard/doc

  cp -a "$pkgname"/* "$pkgdir/usr/share/$pkgname/"

  for tool in $_tools
  do
    cat > "$pkgdir/usr/bin/$tool" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 $tool.py "\$@"
EOF

    chmod +x "$pkgdir/usr/bin/$tool"
  done
}

